package com.itheima.iterator;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class IteratorDemo01 {
    public static void main(String[] args) {
        Collection<String> collection = new ArrayList<>();
        collection.add("a");
        collection.add("b");
        collection.add("c");
        collection.add("d");
        collection.add("e");
        collection.add("e");

        Iterator<String> it2 = collection.iterator();
        while (it2.hasNext()){
            String s = it2.next();
            if ("e".equals(s)){
                it2.remove();//指向谁就删除谁
            }
        }

        Iterator<String> it = collection.iterator();
        while (it.hasNext()){//判断当前索引位置有没有元素
            String result = it.next();//获取当前位置的元素，并将迭代器移向下一个索引位置
            System.out.print(result+" ");//a b c d
        }
    }
}
